package com.fengxing.ams.web.facade.mouble.user;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.google.common.collect.Lists;

@Entity
@Table(name = "zyt_sys_role")
@JsonIgnoreProperties(ignoreUnknown = true)
public class RoleVO implements Serializable {
	private static final long serialVersionUID = -2230242622506904069L;
	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	protected Long role_id;
	private String name;
	private String remarks;
	private Date create_date;

	@ManyToMany(mappedBy = "roleList", fetch = FetchType.LAZY)
	@OrderBy("userId")
	@Fetch(FetchMode.SUBSELECT)
	@NotFound(action = NotFoundAction.IGNORE)
	private List<UserVO> userList; // 拥有用户列表
	
	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "zyt_sys_role_menu", joinColumns = { @JoinColumn(name = "role_id") }, inverseJoinColumns = { @JoinColumn(name = "menu_id") })
	@OrderBy("sort") @Fetch(FetchMode.SUBSELECT)
	@NotFound(action = NotFoundAction.IGNORE)
	private List<MenuVO> menuList; // 拥有菜单列表

	public Long getRole_id() {
		return role_id;
	}

	public void setRole_id(Long roleId) {
		this.role_id = roleId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getRemarks() {
		return remarks;
	}

	public void setRemarks(String remarks) {
		this.remarks = remarks;
	}

	public Date getCreate_date() {
		return create_date;
	}

	public void setCreate_date(Date createDate) {
		this.create_date = createDate;
	}

	public List<UserVO> getUserList() {
		if (null == userList) {
			userList = Lists.newArrayList();
		}
		return userList;
	}

	public void setUserList(List<UserVO> userList) {
		this.userList = userList;
	}

	public List<MenuVO> getMenuList() {
		if(null == menuList) {
			menuList = Lists.newArrayList();
		}
		return menuList;
	}

	public void setMenuList(List<MenuVO> menuList) {
		this.menuList = menuList;
	}

}
